package com.gycode.vpush.consumer.handler;

import com.aliyun.openservices.shade.com.alibaba.fastjson.JSONObject;
import com.gycode.vpush.consumer.handler.base.AbstractHandler;
import com.gycode.vpush.dto.request.SendMessageDTO;
import com.gycode.vpush.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author PC
 */
@Component("handler_webSocket_timely_msg_handler")
@Slf4j
public class WebSocketTimelyMsgHandler extends AbstractHandler {

    @Autowired
    private WebSocketServer webSocketServer;

    @Override
    public boolean handle(String key, String data) {
        log.info("MQ消费webSocket及时消息 ，data:{}", data);
        SendMessageDTO sendMessageDTO = JSONObject.parseObject(data, SendMessageDTO.class);
        webSocketServer.sendTimelyMessage(sendMessageDTO);
        return true;
    }
}
